package com.wwh.tx.homework.dao;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author Albert
 * @date 2024/8/29-15:13
 * @describe
 */
@Repository
public class GoodDAO {
    @Resource
    private JdbcTemplate jdbcTemplate;

    public void updateStock(int id, int stock){
        String sql = "UPDATE good SET stock = stock - ? WHERE id = ?";
        jdbcTemplate.update(sql, stock, id);
    }

    public double queryPriceById(int id){
        String sql = "SELECT price FROM good WHERE id = ?";
        return jdbcTemplate.queryForObject(sql, Double.class, id);
    }

    public int querySellerIdById(int id){
        String sql = "SELECT seller_id FROM good WHERE id = ?";
        return jdbcTemplate.queryForObject(sql, int.class, id);
    }
}
